package com.ec.rs.controller;

import com.ec.common.domain.PageVO;
import com.ec.common.domain.Result;
import com.ec.rs.domain.vo.BedStatsVO;
import com.ec.rs.domain.dto.CreateBedDTO;
import com.ec.rs.domain.dto.UpdateBedDTO;
import com.ec.rs.domain.po.Bed;
import com.ec.rs.service.BedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Api(tags = "床位管理")
@RestController
@RequestMapping("/beds")
@RequiredArgsConstructor
@Slf4j
public class BedController {
    private final BedService bedService;

    @ApiOperation("分页查询床位列表")
    @GetMapping
    public Result<PageVO<Bed>> listBeds(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String roomNumber) {
        return bedService.listBeds(page, size, status, roomNumber);
    }

    @ApiOperation("查询床位详情")
    @GetMapping("/{id}")
    public Result<Bed> getBedById(@PathVariable Integer id) {
        return bedService.getBedById(id);
    }

    @ApiOperation("新增床位")
    @PostMapping
    public Result<Void> createBed(@RequestBody CreateBedDTO dto) {
        return bedService.createBed(dto);
    }

    @ApiOperation("更新床位信息")
    @PutMapping("/{id}")
    public Result<Void> updateBed(@PathVariable Integer id, @RequestBody UpdateBedDTO dto) {
        return bedService.updateBed(id, dto);
    }

    @ApiOperation("删除床位")
    @DeleteMapping("/{id}")
    public Result<Void> deleteBed(@PathVariable Integer id) {
        return bedService.deleteBed(id);
    }

    @ApiOperation("统计床位状态")
    @GetMapping("/stats")
    public Result<BedStatsVO> getBedStats() {
        return bedService.getBedStats();
    }
}